package com.example.zqq.fivechess;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements GameCallBack {

    private FiveChessView fiveChessView;
    private TextView whiteWinTv,blackWinTv;
    private TextView winTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        setContentView(new FiveChessView(this));

        fiveChessView = (FiveChessView) findViewById(R.id.five_chess_view);
        fiveChessView.setCallBack(this);

        whiteWinTv = (TextView) findViewById(R.id.white_count_tv);
        blackWinTv = (TextView) findViewById(R.id.black_count_tv);
        winTv = (TextView) findViewById(R.id.text);
    }

    @Override
    public void GameOver(int winner) {
        //更新游戏胜利局数
        updateWinInfo();
        switch (winner) {
            case FiveChessView.BLACK_WIN:
                showToast("黑棋胜利！");
                break;
            case FiveChessView.NO_WIN:
                showToast("平局！");
                break;
            case FiveChessView.WHITE_WIN:
                showToast("白棋胜利！");
                break;
        }
    }

    @Override
    public void ChangeGamer(boolean isWhite) {

    }



    //更新游戏胜利局数
    private void updateWinInfo() {
        whiteWinTv.setText(fiveChessView.getWhiteChessCount() + " ");
        blackWinTv.setText(fiveChessView.getBlackChessCount()+" ");
    }

    private void showToast(String str) {
        winTv.setVisibility(View.VISIBLE);
        winTv.setText(str);
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.restart_game:
                //重新开始游戏
                winTv.setVisibility(View.GONE);
                fiveChessView.resetGame();
                break;
        }
    }

}
